<template>
  <div class="mainos">
    <div class="main_spac1 paddingBottom5">
      <div class="main_white padding10 paddingBottom20">
        <div class="main_crumbs boxdq">
          <div class="main_crumbs_l">
            <a href="javascript:;" @click="$router.back(-1)">
              <i class="el-icon-arrow-down"></i>返回
            </a>
            <em>|</em>
            <span>查看</span>
          </div>
          <div class="main_crumbs_rt">
            <el-button v-repeatClick class="marginLeft5" @click="print"
              >打印</el-button
            >
            <el-button v-repeatClick class="marginLeft5" @click="export_de"
              >导出</el-button
            >
          </div>
        </div>
        <div class="main_tile boxdq marginTop10">
          <div class="main_tile_l marginLeft0"><em></em>基础信息</div>
        </div>
        <div class="main_xq" v-if="info.info.type == 1">
          <ul class="boxha">
            <li>
              采购单号：<span>{{ info.info.related_order_sn }}</span>
            </li>
            <li>
              采购日期：<span>{{
                info.info.purchase_time
                  ? parseTime(info.info.purchase_time, "{y}-{m}-{d}")
                  : ""
              }}</span>
            </li>
            <li>
              采购方式：<span>{{ info.modeList[info.info.mode] }}</span>
            </li>
            <li>
              采购员/供应商：<span>{{
                info.info.mode == 1
                  ? info.buyer[info.info.buyer_id]
                  : info.supplier[info.info.supplier_id]
              }}</span>
            </li>
            <li>
              对账单号：<span>{{ info.info.order_sn }}</span>
            </li>
            <li>
              采购金额：<span>{{ info.info.money_all }}</span>
            </li>
            <li>
              对账金额：<span>{{ info.info.account_money }}</span>
            </li>
            <li>
              差异金额：<span>{{ info.info.diff_money }}</span>
            </li>
            <li>
              对账状态：<span>{{
                info.account_status_list[info.info.account_status]
              }}</span>
            </li>
            <li>
              结算状态：<span>{{ info.statusList[info.info.status] }}</span>
            </li>
            <li class="main_w100">
              备注：<span>{{ info.remark }}</span>
            </li>
          </ul>
        </div>
        <div class="main_xq" v-else>
          <ul class="boxha">
            <li>
              退货单号：<span>{{ info.info.related_order_sn }}</span>
            </li>
            <li>
              采购方式：<span>{{ info.modeList[info.info.mode] }}</span>
            </li>
            <li>
              采购员/供应商：<span>{{
                info.info.mode == 1
                  ? info.buyer[info.info.buyer_id]
                  : info.supplier[info.info.supplier_id]
              }}</span>
            </li>
            <li>
              对账单号：<span>{{ info.info.order_sn }}</span>
            </li>
            <li>
              退货金额：<span>{{ info.info.money_all }}</span>
            </li>
            <li>
              对账金额：<span>{{ info.info.account_money }}</span>
            </li>
            <li>
              差异金额：<span>{{ info.info.diff_money }}</span>
            </li>
            <li>
              对账状态：<span>{{
                info.account_status_list[info.info.account_status]
              }}</span>
            </li>
            <li>
              结算状态：<span>{{ info.statusList[info.info.status] }}</span>
            </li>
            <li class="main_w100">
              备注：<span>{{ info.info.remark }}</span>
            </li>
          </ul>
        </div>
        <div class="main_tile boxdq marginTop10">
          <div class="main_tile_l marginLeft0"><em></em>商品详情</div>
          <!-- <div class="mainos_tile_r">合计：{{ info.info.money_all }}元</div> -->
        </div>
        <div class="main_table marginTop0" v-if="info.info.type == 1">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="info.info.account_statement_list"
            element-loading-text="加载中"
            fit
            highlight-current-row
            show-summary
            :summary-method="getSummaries"
          >
            <el-table-column label="序号" prop="userId">
              <template slot-scope="scope">{{ scope.$index + 1 }}</template>
            </el-table-column>
            <el-table-column
              label="商品名称"
              width="150"
              prop="name"
              class-name="main_hei"
            >
              <template slot-scope="scope"
                >{{ scope.row.goods.name }}【{{
                  scope.row.goods_spu.spu_name.title
                }}】</template
              >
            </el-table-column>
            <el-table-column
              label="单位"
              prop="goods_spu.spu_unit.title"
              class-name="main_hei"
            />
            <el-table-column
              label="采购数量"
              width="150"
              prop="num"
              class-name="main_hei"
            />
            <el-table-column
              label="采购单价"
              width="150"
              prop="price"
              class-name="main_hei"
            />
            <el-table-column
              label="采购金额"
              width="150"
              prop="price"
              class-name="main_hei"
            >
              <template slot-scope="scope">{{
                (parseFloat(scope.row.price) * parseFloat(scope.row.num))
                  | twoPlace
              }}</template>
            </el-table-column>
            <el-table-column
              label="对账数量"
              width="150"
              prop="account_num"
              class-name="main_hei"
            />
            <el-table-column
              label="对账单价"
              prop="account_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="对账金额"
              prop=""
              width="150"
              class-name="main_hei"
            >
              <template slot-scope="scope">
                {{ $toFixed(parseFloat(scope.row.account_money)) }}
              </template>
            </el-table-column>
            <el-table-column
              label="差异数量"
              prop="diff_num"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异单价"
              prop="diff_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异金额"
              prop="diff_money"
              width="150"
              class-name="main_hei"
            />
            <el-table-column label="备注" prop="remark" class-name="main_hei" />
          </el-table>
        </div>
        <div class="main_table marginTop0" v-else>
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="info.info.account_statement_list"
            element-loading-text="加载中"
            fit
            highlight-current-row
          >
            <el-table-column label="序号" prop="userId">
              <template slot-scope="scope">{{ scope.$index + 1 }}</template>
            </el-table-column>
            <el-table-column
              label="商品名称"
              width="150"
              prop="name"
              class-name="main_hei"
            >
              <template slot-scope="scope"
                >{{ scope.row.goods.name }}【{{
                  scope.row.goods_spu.spu_name.title
                }}】</template
              >
            </el-table-column>
            <el-table-column
              label="单位"
              prop="goods_spu.spu_unit.title"
              class-name="main_hei"
            />
            <el-table-column
              label="退货数量"
              width="150"
              prop="num"
              class-name="main_hei"
            />
            <el-table-column
              label="退货单价"
              width="150"
              prop="account_num"
              class-name="main_hei"
            />
            <el-table-column
              label="退货金额"
              width="150"
              prop="money"
              class-name="main_hei"
            >
            </el-table-column>
            <el-table-column
              label="对账数量"
              width="150"
              prop="account_num"
              class-name="main_hei"
            />
            <el-table-column
              label="对账单价"
              prop="account_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="对账金额"
              prop="account_money"
              width="150"
              class-name="main_hei"
            >
            </el-table-column>
            <el-table-column
              label="差异数量"
              prop="diff_num"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异单价"
              prop="diff_price"
              width="150"
              class-name="main_hei"
            />
            <el-table-column
              label="差异金额"
              prop="diff_money"
              width="150"
              class-name="main_hei"
            />
            <el-table-column label="备注" prop="remark" class-name="main_hei" />
          </el-table>
        </div>
        <div class="main_tile boxdq marginTop10">
          <div class="main_tile_l marginLeft0"><em></em>其他</div>
        </div>
        <div class="main_xq">
          <ul class="boxha">
            <li
              class="main_w100 box marginTop15 marginBottom15"
              v-for="(other_list, index) in other_list"
              :key="index"
            >
              <p class="base_p">{{ index == 0 ? "其他费用：" : "" }}</p>
              <div class="box main_xqi" style="margin-top: -4px">
                <el-input
                  v-model.trim="other_list.descr"
                  disabled
                  placeholder="描述"
                  clearable
                  class="wid240"
                ></el-input>
                <el-input
                  v-model.trim="other_list.money"
                  placeholder="金额"
                  disabled
                  clearable
                  class="wid140 marginLeft15"
                ></el-input>
              </div>
            </li>
            <li class="main_w100">
              合计：<span>{{ info.info.account_money }}</span>
            </li>
            <!-- <li class="main_w100 box marginTop20" v-if="info.info.remark">
              备注：
              <div class="box main_xqi" style="margin-top: -4px">
                <el-input
                  disabled
                  v-model.trim="info.info.remark"
                  placeholder="备注"
                  clearable
                ></el-input>
              </div>
            </li> -->
            <li class="main_w100 box marginTop20">
              显示相关凭证：
              <div class="box main_xqi">
                <div
                  class="main_xqi_i marginRight10"
                  v-for="(pics, index) in info.info.pics"
                  :key="index"
                >
                  <label
                    class="el-upload-list__item-status-label"
                    v-if="pics.includes(info.info.pic)"
                  >
                    <i class="el-icon-upload-success el-icon-check"></i>
                  </label>
                  <el-image
                    fit="fill"
                    :src="pics"
                    :preview-src-list="info.info.pics"
                  >
                    <div slot="error" class="image-slot">
                      <img :src="puzzleImg" />
                    </div>
                  </el-image>
                </div>
              </div>
            </li>
          </ul>
        </div>
        <div class="main_tile boxdq marginTop20">
          <div class="main_tile_l marginLeft0"><em></em>生命周期</div>
        </div>
        <div class="main_table marginTop0">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="info.logs"
            element-loading-text="加载中"
            fit
            highlight-current-row
          >
            <el-table-column
              label="管理员"
              prop="admin.name"
              class-name="main_hei"
            />
            <el-table-column
              label="操作"
              prop="operate.name"
              class-name="main_hei"
            />
            <el-table-column label="内容" prop="content" class-name="main_hei">
              <template slot-scope="scope">
                <div
                  v-for="(content, index) in scope.row.content"
                  :key="index"
                  class="marginTop5 marginBottom5"
                >
                  {{ content }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="IP" prop="ip" class-name="main_hei" />
            <el-table-column
              label="时间"
              prop="created_at"
              class-name="main_hei"
            >
              <template slot-scope="scope">{{
                parseTime(scope.row.created_at)
              }}</template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <!-- 打印子组件 -->
    <order-print
      ref="printTemplate"
      v-show="false"
      id="printname"
    ></order-print>
  </div>
</template>

<script>
import {
  account_info,
  export_AccountStatement,
} from "@/api/financial/financialRecharge";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime, exportMethod } from "@/utils/index";
import OrderPrint from "@/views/order/orderPrint.vue";
import { puzzleImg } from "@/api/currency";

import { mapGetters } from "vuex";
export default {
  components: { OrderPrint },
  computed: {
    ...mapGetters(["avatar"]),
    total() {
      let dz = 0;
      this.info.info.account_statement_list.forEach((e) => {
        dz += parseFloat(this.$toFixed(parseFloat(e.account_money)));
      });
      dz = dz ? this.$toFixed(dz) : "0.00";
      return { dz };
    },
  },

  data() {
    return {
      // 时间
      parseTime,
      exportMethod,
      puzzleImg,
      // 基本信息
      info: {
        info: {
          money: 0,
          created_at: "2000-01-01",
          type: 0,
          status: 0,
          mode: 0,
          account_statement_list: [],
          pics: [],
        },
        buyer: ["未分拣"],
        modeList: ["未分拣"],
        supplier: ["未分拣"],
        typeList: ["未分拣"],
        account_status_list: ["未分拣"],
        statusList: ["未分拣"],
      },
      listLoading: false,
      // id
      id: this.$route.params.id,
      other_list: [],
      pics: [],
      remark: "",
    };
  },
  created() {
    // 基本信息
    this.account_info();
  },
  methods: {
    // 基本信息
    account_info() {
      let data = Object.assign(
        apiUrl().name,
        { id: this.id }
      );
      account_info(data).then((res) => {
        if (res.errcode == 0) {
          res.data.logs.map((e) => {
            if (e.content) {
              e.content = JSON.parse(e.content);
            }
          });
          let other_list = [];
          other_list = JSON.parse(res.data.info.other_money);
          other_list.map((e, index, arr) => {
            if (e.descr == "" && e.money == "") {
              arr.splice(index, 1);
            }
          });
          this.other_list = other_list;
          if (res.data.info.pics) {
            res.data.info.pics = res.data.info.pics
              .split(",")
              .map((p) => this.avatar.domain + p);
          }
          this.info = res.data;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 导出
    export_de() {
      let data = Object.assign(
        apiUrl().name,
        { id: this.id }
      );
      export_AccountStatement(data)
        .then((res) => {
          this.exportMethod(res, "采购账单详情");
        })
        .catch((err) => {
          this.$message.error("导出失败");
        });
    },
    // 打印
    print() {
      let id = this.id;
      this.$refs.printTemplate.$emit("demo", { id: id, type: "account" });
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        switch (index) {
          case 0:
            sums[index] = "合计";
            break;
          case 8:
            sums[index] = this.$toFixed(this.total.dz);
            break;
        }
      });

      return sums;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainos {
  .main_tile {
    .mainos_tile_r {
      color: $colour_red;
      font-size: $font_14;
    }
  }
  .mainor_ex {
    position: fixed;
    width: 220px;
    height: 100%;
    background: $white;
    box-shadow: 0 6px 10px rgba(0, 21, 41, 0.08);
    top: 0;
    right: 0;
    z-index: 9999;
    transition: all 0.5s;
    transform: translate3d(100%, 0, 0);
    &.on {
      transform: translate3d(0, 0, 0);
    }
    .mainor_exb {
      position: absolute;
      width: 100%;
      height: calc(100% - 60px);
      overflow-y: auto;
      h3 {
        font-size: $font_16;
        color: $colour_18;
        height: 50px;
        line-height: 50px;
        border-bottom: 1px solid $colour_e6;
        padding-left: 20px;
      }
      .mainor_exb_an {
        padding-left: 20px;
        margin-top: 15px;
        /deep/.el-checkbox {
          display: block;
          margin-top: 15px;
          margin-bottom: 15px;
        }
      }
    }
    .mainor_exb_b {
      position: absolute;
      bottom: 0;
      width: 100%;
      border-top: 1px solid $colour_e6;
      height: 55px;
      text-align: center;
      /deep/.el-button--default {
        margin-top: 12px;
        border-color: $subActive;
        color: $menuText;
        &:hover {
          border-color: $menuActiveText;
          color: $menuActiveText;
        }
      }
    }
  }
}
/deep/.el-image .el-image__inner {
  width: 120px;

  border: 1px solid #f8f8f9;
  margin-right: 20px;
}
/deep/.el-image .image-slot img {
  width: 120px;
  border: 1px solid #f8f8f9;
  margin-right: 20px;
}
.main_xqi {
  width: 80%;
  margin-left: 5px;
}
.main_upImg {
  /deep/ul {
    li {
      padding-left: 0;
    }
  }
  /deep/.el-upload-list--picture-card .el-upload-list__item:first-child {
    margin-left: 145px;
  }
}
</style>
